﻿using System.Windows.Forms;

using Ledict.Utility.Helper;

namespace Ledict.ConditionExtract.Base
{

    /// <summary>
    /// 基础窗体，继承Form
    /// </summary>
    public partial class BaseForm : Form
    {
        #region 常用变量
        /// <summary>
        /// 日志帮助类
        /// </summary>
        //protected LogHelper LogHelper; 
        #endregion

        #region 单例模式（未用）
        //private static object _lock = new object();

        //private static T _instance;

        //public static T Instance
        //{
        //    get
        //    {
        //        if (_instance == null || _instance.IsDisposed)
        //        {
        //            lock (_lock)
        //            {
        //                if (_instance == null || _instance.IsDisposed)
        //                {
        //                    _instance = new T();
        //                }
        //            }
        //        }
        //        return _instance;
        //    }
        //} 
        #endregion

        #region 构造函数
        public BaseForm()
        {
            InitializeComponent();
            //LogHelper = LogFactory.GetLogger();
        }
        #endregion

        //解决打开界面窗口闪烁问题
        //protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } }


        #region 显示窗体，自动将窗体填满父窗体的工作区
        /// <summary>
        /// 显示窗体，自动将窗体填满父窗体的工作区
        /// </summary>
        /// <param name="childForm"></param>
        public virtual void ShowForm(Form childForm)
        {
            if (childForm.MdiParent == null)
            {
                childForm.MdiParent = this;
            }
            childForm.StartPosition = FormStartPosition.CenterParent;
            childForm.Show();
            childForm.Activate();//激活焦点
            childForm.Dock = DockStyle.Fill;

            //窗体是否最大化
            if (ConfigHelper.AppSettings("MidFormMax").Equals("true"))
            {
                childForm.WindowState = FormWindowState.Maximized;//最大化
            }
            #region 未用
            //var size = childForm.Size;
            //var location = childForm.Location;
            //////childForm.Dock = DockStyle.None;
            //childForm.Size = size;
            //childForm.Location = location; 
            #endregion
        } 
        #endregion

    }
}
